from datetime import datetime

from blog import db


class Post(db.Model):
    """文章模型
    字段
        id: 唯一标识
        title: 文章标题
        content: 文章内容
        created: 创建时间
        user_id: 创建该文章的用户ID
    """
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), nullable=False)
    content = db.Column(db.Text, nullable=False)
    created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f'Post({self.title}, {self.created})'
